// ----------------------------------------------------------------------------
// binary_writer.h
// ----------------------------------------------------------------------------
/*
 Description:
 バイナリデータを作成するための補助クラス.
 簡単なチャンクデータ形式のデータ構造を作成する場合に利用します.
 
 ----------------------------------------------------------------
 使い方.

 
 
 */
#ifndef FW_BASE_BINARY_WRITER_H
#define FW_BASE_BINARY_WRITER_H
#include <fw/base/core/macros.h>
#include <fw/base/core/stdinteger.h>
#include <ostream>

namespace fw
{
	class BinaryWriterImpl;
	class Writable;
	class ChildNode;
	class DataNode;
	class PreswappedDataNode;
	class AlignNode;

	enum Endianess
	{
		kLittleEndian,
		kBigEndian,
	}; // enum Endianess 

	enum OffsetOrigin
	{
		kTopOfFile,
		kOffsetAddress,
	}; // enum OffsetOrigin 
	
	enum OffsetByteCount
	{
		kOffset8Bit  = 1,
		kOffset16Bit = 2,
		kOffset32Bit = 4,
		kOffset64Bit = 8,
	}; // enum OffsetByteCount 
	
	
	class BinaryWriter
	{
	private:
		BinaryWriterImpl*	m_impl;
	public:
		
		typedef unsigned int Label;
		
		 BinaryWriter();
		~BinaryWriter();

		BinaryWriter*				AppendChild();
		void						AppendData(const void* data,
											   const unsigned int elementSize,
											   const unsigned int elementCount );
		template<typename T> void	AppendData(T data);
		
	protected:
		
		virtual size_t		GetDataSize(size_t offset) const;
		virtual void		WriteData(std::ostream& out, Endianess endianess) const;
		virtual void		WriteTag (std::ostream& out, Endianess endianess, OffsetOrigin origin) const;
		
	}; // class BinaryWriter 
	
	
} // namespace fw

#endif // FW_BASE_BINARY_WRITER_H
